package com.ynr.common.utils;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Objects;

import sun.misc.BASE64Encoder;

public class ImageToBase64 {

	public static String convert(String imgPath) {
	    byte[] data = null;
	    try {
	        InputStream in = new FileInputStream(imgPath);
	        data = new byte[in.available()];
	        in.read(data);
	        in.close();
	    } catch (IOException e) {
	        e.printStackTrace();
	    }
	    BASE64Encoder encoder = new BASE64Encoder();
	    return encoder.encode(Objects.requireNonNull(data));
	}
	
	public static void main(String[] args) {
		convert("D:/invoice/2018_09_19_14_15_17.jpg");
	}
	
}
